<template>
	<view class="changePwd">
		<custom-navi :show-home="false" background='rgba(0, 144, 250, 1)'>修改密码</custom-navi>
		<view class="changePwd-input">
			<view class="list" v-for="(item,index) in listPwd" :key='index'>
				<view class="list-title">{{item.title}}</view>
				<view class="list-txt"><input type="password" value="" :placeholder="item.pla" placeholder-style="font-size:28rpx;" @blur="importBtn($event,item)"/></view>
			</view>
		</view>
		<view class="changePwd-achieve" @tap="upBtn">完成</view>
	</view>
</template>

<script>
	import {changePasswordByOriginalPassword,getStoreInformation} from "../../../api.js"
	export default{
		data(){
			return{
				listPwd:[
					{title:'原密码',pla:'请输入原密码',value:''},
					{title:'新密码',pla:'6-16位，必须包含数字和字母',value:''},
					{title:'确认密码',pla:'6-16位，必须包含数字和字母',value:''}
				]
			}
		},
		onLoad() {
			
		},
		methods:{
			importBtn(e,item){ // 输入
				item.value = e.detail.value
			},
			async upBtn(){ // 提交
				let _this = this
				for(var i=0;i<this.listPwd.length;i++){
					if(this.listPwd[i].value ===''){
						return this.$utils.common.toast.fail(this.listPwd[i].title+"不能为空");
					}else if(this.listPwd[i].value.length <6 || this.listPwd[i].value.length>16){
						return this.$utils.common.toast.fail('密码6-16位，必须包含数字和字母');
					}
				}
				if(this.listPwd[0].value === this.listPwd[1].value){
					return this.$utils.common.toast.fail('所输入的新旧密码一致');
				}else if(this.listPwd[1].value != this.listPwd[2].value){
					return this.$utils.common.toast.fail('新密码输入不一致');
				}
				uni.showLoading({
				    title: '数据提交中'
				});
				let params = {
				  originalPassword:this.listPwd[0].value,
				  password:this.listPwd[1].value
				}
				try {
				  const {
				    data
				  } = await changePasswordByOriginalPassword(params)
				 console.log(data)
				 uni.setStorageSync('USER_INFO', data)
				 this.$utils.common.toast.fail("修改成功");
				 setTimeout(function () {
				     uni.hideLoading();
				 	_this.$utils.common.toast.fail('修改完成');
				 	setTimeout(function () {
				 		_this.$utils.common.navigateBack()
				 	}, 1000);
				 }, 500);
				} catch (err) {
				  console.log(err)
				  if(err.data.code != 200){
					  setTimeout(function () {
					      uni.hideLoading();
					  	return _this.$utils.common.toast.fail(err.data.message);
					  	
					  }, 500);
				  }
				  // if (err.code && err.statusCode) {
				  //   if (err.data.code != 200) {
						// setTimeout(function () {
						//     uni.hideLoading();
						// 	return _this.$utils.common.toast.fail(err.data.message);
							
						// }, 500);
				  //   }
				  //   setTimeout(function () {
				  //       uni.hideLoading();
				  //   	return _this.$utils.common.toast.fail(err.data.message);
				    	
				  //   }, 500);
				  // }
				}
				
				
				
			}
		}
	}
</script>

<style lang="scss">
	.changePwd{
		&-achieve{
			width:686rpx;
			height:88rpx;
			background:rgba(0,144,250,1);
			opacity:0.64;
			font-size:36rpx;
			font-family:PingFang SC;
			font-weight:500;
			line-height:88rpx;
			color:rgba(255,255,255,1);
			text-align: center;
			border-radius: 10rpx;
			margin: 0 auto;
			margin-top: 86rpx;
		}
		&-input{
			width:750rpx;
			
			background:rgba(255,255,255,1);
			opacity:1;
			.list{
				padding: 22rpx 32rpx;
				display: flex;
				align-items: center;
				border-bottom: 2rpx solid rgba(217, 217, 217, 1);
				font-size:28rpx;
				&-title{
					font-size:28rpx;
					font-family:PingFang SC;
					font-weight:400;
					color:rgba(80,80,80,1);
					opacity:1;
					margin-right: 58rpx;
				}
				&-txt{
					
				}
			}
			.list:last-child{
				border-bottom: none;
				// display: none;
			}
		}
	}
</style>
